<?php
defined('BASEPATH') OR exit('No direct script access allowed');
	class Article_model extends My_Model{
        public $table_name='article';
    	public function get_list_catalog_id($catalog_id){
	    	$query = $this->db->where('catalog_id',$catalog_id)->get($this->table_name);
	        return $query->result();
    	}
        public function view_once($id){
            $this->db->query("update $this->table_name set `view`=`view`+1 where `id`= $id");
        }
        public function count_all(){
           return  $this->db->count_all_results($this->table_name);
        }
        public function get_page($page,$pageSize){
            $offset=($page-1)*$pageSize;
            $query=$this->db->limit($pageSize,$offset)->order_by('id', 'DESC')->get($this->table_name);
            return $query->result();
        }
        public function get_article_recommend($id){
            $query=$this->db->where('id',$id)->get($this->table_name);
            $arr=$query->row();
            $data=$arr->recommend==1?0:1;
            $array=array(
                    'recommend'=>$data
                );
            $this->db->update($this->table_name, $array, "id=$id");
            //echo $this->db->last_query();
        }

        //推荐的另一种写法
        // public function get_recommend($id,$v){
        //     $this->db->where('id',$id)->get($this->table_name);
        //     $data=array(
        //             'recommend'=>$v
        //         );
        //     $this->db->update($this->table_name, $data, "id=$id");
        // }
	}